<!DOCTYPE html>

<html ng-app="myApp">
<head>
    <script src="http://code.angularjs.org/1.2.25/angular.min.js"></script>
</head>

<body ng-controller="DemoController as demo">
Client ID: {{demo.clientId}}
<br/>
apiToken: {{demo.apiToken}}
</body>

<script type="text/javascript">
    var myApp = angular.module('myApp', []);

    myApp.factory('clientId', function clientIdFactory() {
        return 'a12345654321x';
    });

    myApp.factory('apiToken', ['clientId', function apiTokenFactory(clientId) {
        var encrypt = function(data1, data2) {
            // NSA-proof加密算法：
            return (data1 + ':' + data2).toUpperCase();
        };

        var secret = window.localStorage.getItem('myApp.secret');
        var apiToken = encrypt(clientId, secret);

        return apiToken;
    }]);

    myApp.controller('DemoController', ['clientId', 'apiToken', function DemoController(clientId, apiToken) {
        this.clientId = clientId;
        this.apiToken = apiToken;
    }]);
</script>
</html>